<template>
  <div class="container">
    <van-nav-bar
      class="app-nav-bar"
      title="意见反馈"
      left-arrow
      @click-left="$router.back()"
    />
    <van-form input-align="right" @submit="onSubmit">
      <van-field
        readonly
        clickable
        name="picker"
        :value="feedbackInfo.feedbackType"
        label="反馈类型"
        placeholder=""
        @click="showPicker = true"
      />
      <van-field
        v-model="feedbackInfo.textarea"
        name="反馈内容"
        label="反馈内容"
        placeholder="反馈内容"
        type="textarea"
        rows="4"
        autosize
        maxlength="150"
        show-word-limit
        :rules="[{ required: true, message: '请填写反馈内容' }]"
      />
      <van-field
        v-model="feedbackInfo.mobile"
        name="联系方式"
        label="联系方式"
        placeholder="联系方式"
        readonly
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
      <van-popup v-model="showPicker" position="bottom">
        <van-picker
          show-toolbar
          :columns="columns"
          @confirm="onConfirm"
          @cancel="showPicker = false"
        />
      </van-popup>
      <div class="login-btn-wrap">
        <van-button
          class="login-btn"
          type="info"
          block
        >提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { createFeedback } from '@/api/feedback'
export default {
  name: '',
  components: {},
  props: {},
  data () {
    return {
      feedbackInfo: {
        feedbackType: '',
        mobile: '',
        textarea: '',
        time: '',
        status: 0,
        msg: ''
      },
      columns: ['功能异常', '产品建议'],
      showPicker: false,
      fileList: []
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {
    this.feedbackInfo.mobile = this.$store.state.user.mobile
    // this.$set(this.feedbackInfo, 'mobile', this.$store.state.user.mobile)
  },
  methods: {
    onConfirm (value) {
      this.feedbackInfo.feedbackType = value
      this.showPicker = false
    },
    onSubmit () {
      console.log('点击按钮', this.feedbackInfo)
      this.feedbackInfo.time = +new Date()
      createFeedback(this.feedbackInfo).then(res => {
        console.log('createFeedback', res)
        this.$toast.success('提交成功')
        history.go(-1)
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style scoped lang="scss">
.avatar {
  width: 66px;
}
.van-cell__title, .van-cell__value {
  margin: auto 0;
}
.login-btn-wrap {
  padding: 26px 16px;
  .login-btn {
    background-color: #6db4fb;
    border: none;
    .van-button__text {
      font-size: 15px;
    }
  }
}
</style>
